﻿// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_BPT_APP
// * CreateDate    : 2013-10-25 14:26:10
// * Creater       : CodeSmith
// * LastChangeDate: 2013-10-25 14:26:10
// * LastChanger   : 2013-10-25 14:26:10
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;
using ESOL.Business.Mst;

namespace ESOL.Business.Sales
{
    /// <summary>
    /// BptApp
    /// </summary>
    public partial class BptAppBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objBptAppEntity">Entity</param>
        /// <returns>Entity</returns>
        public static BptAppEntity GetBptApp(BptAppEntity objBptAppEntity)
        {
            return DataAccess.SelectSingle<BptAppEntity>(objBptAppEntity);
        }
        #endregion


        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objBptAppEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertBptApp(BptAppEntity objBptAppEntity)
        {
            return DataAccess.Insert(objBptAppEntity);
        }

        public static bool InsertBptApp(List<BptAppEntity> objBptAppEntityList)
        {
            return DataAccess.Insert(objBptAppEntityList);
        }
        #endregion


        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objBptAppEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateBptApp(BptAppEntity objBptAppEntity)
        {
            return DataAccess.Update(objBptAppEntity);
        }

        public static bool UpdateBptApp(List<BptAppEntity> objBptAppEntityList)
        {
            return DataAccess.Update<BptAppEntity>(objBptAppEntityList);
        }
        #endregion


        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objBptAppEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteBptApp(BptAppEntity objBptAppEntity)
        {
            return DataAccess.Delete(objBptAppEntity);
        }

        public static bool DeleteBptApp(List<BptAppEntity> objBptAppEntityList)
        {
            return DataAccess.Delete<BptAppEntity>(objBptAppEntityList);
        }
        #endregion


        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetBptAppAll()
        {
            return DataAccess.SelectAllDataSet<BptAppEntity>();
        }

        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<BptAppEntity> GetBptAppAllList()
        {
            return DataAccess.SelectAll<BptAppEntity>();
        }
        #endregion

        public static DataSet GetAllByCondition(int pageIndex, int pageCount, string condition)
        {
            string sql = "";
            if (string.IsNullOrEmpty(condition))
            {
                string sqlSource = @"select top {0} *,(select count(1) from bpt_app) as cnt
from bpt_app
where id not in (
    select top ({1}*({2}-1)) id from bpt_app order by created_date
) order by created_date desc";
                sqlSource = string.Format(sqlSource, pageCount, pageCount, pageIndex);
                sql = @"select BA.*,APP.APP_NO AS SALES_APP_NO
from ({0}) BA
left join SALES_APP APP on BA.SALES_APP_ID=APP.ID";
                sql = string.Format(sql, sqlSource);
            }
            else
            {
                sql = @"select top {0} *,(select count(1) from ({3}) t) as cnt
from ({3}) t
where t.id not in (
    select top ({1}*({2}-1)) id from ({3}) t order by created_date
) order by created_date desc";
                string sqlSource = @"select BA.*,APP.APP_NO AS SALES_APP_NO
from bpt_app BA
left join SALES_APP APP on BA.SALES_APP_ID=APP.ID
where 1=1 ";
                sqlSource += condition;
                sql = string.Format(sql, pageCount, pageCount, pageIndex, sqlSource);
            }
            return DataAccess.SelectDataSet(sql);
            
        }


    }


}

